---
title: "C# Lambda Expression Tree 测试"
date: 2015-5-11 16:51
categories:
- dotnet
tags:
---

<div id="content">
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org702f80c">BinaryExpression 二元表达式:</a></li>
</ul>
</div>
</div>
<div class="outline-2" id="outline-container-org702f80c">
<h2 id="org702f80c">BinaryExpression 二元表达式:</h2>
<div class="outline-text-2" id="text-org702f80c">
<p>
Expression&lt;Func&lt;T_User,bool&gt;&gt; expression = c {% raw %} &gt; c.id = {% endraw %} id &amp;&amp; c.UserId == "2";
var bodyExpression = expression.Body as BinaryExpression;//二元表达式
</p>
<p>
bodyExpression.Left: 	c.id==id
bodyExpression.Right: 	c.UserId=="2"
</p>
<p>
Expression&lt;Func&lt;T_User,bool&gt;&gt; expression = c {% raw %} &gt; c.id = {% endraw %} id &amp;&amp; c.UserId {% raw %} = "2" &amp;&amp; c.Sex = {% endraw %} 1;
var bodyExpression = expression.Body as BinaryExpression;//二元表达式
</p>
<p>
bodyExpression.Left:	c.id==id andalso c.UserId=="2"
bodyExpression.Right:	c.Sex==1
</p>
<p>
Expression&lt;Func&lt;T_User,bool&gt;&gt; expression = c {% raw %} &gt; c.id = {% endraw %} id &amp;&amp; (c.UserId {% raw %} = "2" || c.Sex = {% endraw %} 1);
var bodyExpression = expression.Body as BinaryExpression;//二元表达式
</p>
<p>
bodyExpression.Left:	c=&gt;c.id
bodyExpression:Right:	c.UserId=="2" OrElse c.Sex==1
</p>
</div>
</div>
</div>
<div class="status" id="postamble">
<p class="date">Date: 2015-5-11 16:51</p>
<p class="author">Author: gdme1320</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
